/*
 * @Author: master
 * @Date: 2022-04-08 13:23:43
 * @LastEditTime: 2022-04-12 15:11:43
 * @Description: 别名
 */
const path = require('path');
/**
 * 获取别名
 * @param {Object} viteConfig
 */
export default function alias(viteConfig) {
  const defaultAlias = [
    // @映射到main目录
    {
      find: '@',
      replacement: path.join(__dirname, '../..', 'main'),
    },
    // 当前项目地址别名
    {
      find: '@path',
      replacement: viteConfig.root,
    },
    // 解决vue-i18n警告You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
    {
      find: 'vue-i18n',
      replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
    },
    // compile template，Vue的这个构建中不支持运行时编译，vite基于现代浏览器的特点，先查找相关的引用，然后在编译，在运行
    {
      find: 'vue',
      replacement: 'vue/dist/vue.esm-bundler.js',
    },
  ];
  // 地图3d模式
  if (viteConfig?.map && viteConfig.map === '3d') {
    defaultAlias.push({
      find: 'cesium',
      replacement: path.join(__dirname, '../..', 'node_modules/cesium'),
    });
  }
  return defaultAlias;
}
